package com.mid;

import java.util.*;

/**
 * Created by Lxk on 2020/1/27.
 */
public class Solution90 {

    private List<List<Integer>> res = new ArrayList<>();

    Map<String, String> help = new HashMap<>();

    private void findSub(int[] nums, int pos, Stack<Integer> stack) {
        if (pos == nums.length) {
            List<Integer> curList = new ArrayList<>();
            for (Integer val : stack) {
                curList.add(val);
            }
            Collections.sort(curList);
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < curList.size(); i++) {
                sb.append(curList.get(i));
                sb.append("-");
            }
            if (help.put(sb.toString(), "") == null) {
                res.add(curList);
            }
        } else {
            stack.push(nums[pos]);
            findSub(nums, pos + 1, stack);
            stack.pop();
            findSub(nums, pos + 1, stack);
        }
    }

    public List<List<Integer>> subsetsWithDup(int[] nums) {
        if (nums == null || nums.length == 0) {
            res.add(new ArrayList<>());
            return res;
        }
        Stack<Integer> stack = new Stack<>();
        findSub(nums, 0, stack);
        return res;
    }

    public static void main(String[] args) {
        Solution90 solution90 = new Solution90();
        int[] nums = {1, 2, 3};
        System.out.println(solution90.subsetsWithDup(nums));
    }

}
